package top.ddandang.blog.service.impl;

import top.ddandang.blog.model.pojo.PersonalInfo;
import top.ddandang.blog.mapper.PersonalInfoMapper;
import top.ddandang.blog.service.PersonalInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import top.ddandang.blog.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author D
 * @since 2020-07-15
 */
@Service
public class PersonalInfoServiceImpl extends ServiceImpl<PersonalInfoMapper, PersonalInfo> implements PersonalInfoService {

    @Resource
    private PersonalInfoMapper personalInfoMapper;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public PersonalInfo getInformationById(Integer id) {

        String key = "personalInfo:" + id;
        PersonalInfo personalInfo = null;
        if(redisUtil.hasKey(key)) {
            personalInfo = (PersonalInfo) redisUtil.get(key);
        }else {
            personalInfo = personalInfoMapper.selectById(id);
            redisUtil.set(key, personalInfo);
        }
        return personalInfo;
    }
}
